const path = require('path');

function parseConfig(currentPath, config) {
    const result = {};

    function traverse(currentPath, currentConfig) {
        if (currentConfig.regexp) {
            result[currentPath] = {
                regexp: currentConfig.regexp,
                whitelist: currentConfig.whitelist || [],
            };
        }

        if (currentConfig.directories) {
            for (const [directory, options] of Object.entries(
                currentConfig.directories
            )) {
                const fullPath = path.join(currentPath, directory);
                traverse(fullPath, options);
            }
        }
    }

    traverse(currentPath, config);

    return result;
}

module.exports = parseConfig;